package code;

import java.util.Scanner;

public class TUI implements IUI {
	
	private String			 input;
	@SuppressWarnings("unused") // Bliver brugt til at få informationer til vægtens display
	private WeightController weight;
	private Scanner			 scan = new Scanner(System.in);

	@Override
	public void run() {
		
		String hold;

		while (true)
		{
			hold = scan.nextLine();
			input = hold;
			synchronized (this) {
				try {
					wait();
					
				} catch (InterruptedException e) {}
				
			}
		
		}
		
	}

	@Override
	public void updateScreen(WeightController weight) {
		this.weight = weight;
	
		System.out.println("********************************************************");
		System.out.println("* Nettovægt   : " + weight.getDisplay(1));
		System.out.println("* P111 display: " + weight.getDisplay(2));
		System.out.println("* RM besked   : " + weight.getDisplay(3));
		System.out.println("********************************************************");
	}

	
	@Override
	public synchronized String respondRM20() {
		
		
		System.out.println("Indtast dit RM20 svar, og bekræft enter");
		
		synchronized (System.in) {
			System.in.notify();
		}
			System.out.println(input);
		String result = "RM20 A " + input;
		
		
		return result;
	}

	@Override
	public String getInput() {
		
		String result = null;
		
		if (input != null)
		{
			result = input;
			input = null;
		}
		
		return result;
	}

}
